package com.moco.launcher.adapter;

import java.util.ArrayList;
import java.util.List;

import com.moco.launcher.R;
import com.moco.launcher.bean.PickItemInfo;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SettingListAdapter extends ArrayAdapter<PickItemInfo> {

	private static final String TAG = "SettingListAdapter";

	List<PickItemInfo> mList = new ArrayList<PickItemInfo>();

	public SettingListAdapter(Context context, int resource,
			List<PickItemInfo> objects) {
		super(context, resource, objects);
		mList = objects;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		RelativeLayout layout = null;

		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) this.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			layout = (RelativeLayout) inflater.inflate(
					R.layout.item_list_image, layout);
		} else {
			layout = (RelativeLayout) convertView;
		}

		PickItemInfo item = mList.get(position % mList.size());
		ImageView imgview = (ImageView) layout.findViewById(R.id.image);
		TextView textView = (TextView) layout.findViewById(R.id.text);
		ImageView backview = (ImageView) layout.findViewById(R.id.back);

		Log.d(TAG, "position = " + position + " " + mList.size() / 2);

		if (position == (mList.size() / 2)) {
			backview.setImageResource(item.getBackIconId());
			backview.setVisibility(View.VISIBLE);
			imgview.setImageResource(item.getLeftIconLight());
			textView.setTextSize(28);
			textView.setText(item.getText());
		} else {
			backview.setVisibility(View.GONE);
			imgview.setImageResource(item.getLeftIconDark());
			textView.setTextSize(24);
			textView.setText(item.getText());
		}

		return layout;

	}
}
